package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.common.utils.ToastUtils;
import com.ldc.wandroid.model.SystemModel;
import com.ldc.common.net.Api2Request;
import com.ldc.wandroid.server.ApiServer;

import java.util.List;

public class SystemViewModel extends ViewModelBase {
    private final ApiServer apiServer = Api2Request.getInstance().createServer(ApiServer.class);

    private final MutableLiveData<List<SystemModel>> stsData = new MutableLiveData<>();

    public LiveData<List<SystemModel>> getSystemData() {
        return stsData;
    }

    public void loadSystem() {
        apiRequest(apiServer.get_system(), (status, result, throwable) -> {
            if (result.isSuccess()) {
                stsData.setValue(result.getData());
            } else {
                stsData.setValue(null);
                ToastUtils.showShort(throwable);
            }
        });
    }
}
